package se.hh.service;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import se.hh.lab.dao.UserDao;
import se.hh.lab.dao.UserLoginDao;
import se.hh.lab.dao.impl.UserDaoImpl;
import se.hh.lab.dao.impl.UserLoginDaoImpl;
import se.hh.lab.domain.Login;
import se.hh.lab.domain.User;

public class UserModifyInfo extends HttpServlet
{


	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException
	{
		HttpSession session=request.getSession();
		User user=(User)session.getAttribute("user");
		Login login=(Login)session.getAttribute("userlogin");
//		
//		System.out.println(user.getUserID());
//		System.out.println(user.getLastname());
//		System.out.println(user.getFirstname());
//		System.out.println(login.getLoginID());
//		System.out.println(user.getGender());
//		System.out.println(user.getStatus());
		
		if(login==null)
		{
			response.sendRedirect("user_main.jsp");  //if login you are go on else main.jsp
			return;
		}
		else
		{
			String firstname=request.getParameter("firstname");
			String lastname=request.getParameter("lastname");
			String age=request.getParameter("age");
			String email=request.getParameter("email");
			String phone=request.getParameter("phone");
			user.setFirstname(firstname);
			user.setLastname(lastname);
			user.setAge(age);
			user.setEmail(email);
			user.setPhone(phone);
		
			String loginID=request.getParameter("login_id");
			String password=request.getParameter("password");
			login.setLoginID(loginID);
			login.setPassword(password);
		


			UserDao userDao=new UserDaoImpl();
			UserLoginDao userLoginDao=new UserLoginDaoImpl();
			
			
			int k=userDao.updateUser(user);
			int f=userLoginDao.updateUserLogin(login);
			
			if(k==1 && f==1)
				
			request.getRequestDispatcher("user_personalInfo.jsp").forward(request, response);

			
		}
	}


	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException
	{

		this.doGet(request, response);
	}

}
